class Admin::RefundReasonsController < AdminController
  def index
    @refund_reasons = RefundReason.all.order("sort ASC").page(params[:page]).per(params[:per])
  end

  def new
    @refund_reason = RefundReason.new
  end

  def create
    @refund_reason = RefundReason.new refund_reason_params
    if @refund_reason.save
      redirect_to admin_refund_reasons_path, notice: "保存成功！"
    else
      redirect_to admin_refund_reasons_path, notice: "保存失败！"
    end
  end

  def edit
    @refund_reason = RefundReason.find params[:id]
  end

  def update
    @refund_reason = RefundReason.find params[:id]
    if @refund_reason.update refund_reason_params
      redirect_to admin_refund_reasons_path, notice: "更新成功！"
    else
      redirect_to admin_refund_reasons_path, notice: "更新失败！"
    end
  end
  
  def destroy
    @refund_reason = RefundReason.find params[:id]
    if @refund_reason.destroy
      redirect_to admin_refund_reasons_path, notice: "删除成功."
    else
      redirect_to admin_refund_reasons_path, notice: "删除失败."
    end
  end

  private

  def refund_reason_params
    params.require(:refund_reason).permit(:name, :published, :sort)
  end
end
